package com.fjb.service.user.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonTotalResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.common.enums.user.UserType;
import com.fjb.mapper.user.SysUserMapper;
import com.fjb.pojo.user.SysUser;
import com.fjb.service.user.SysUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * <p>
 * 用户信息 服务实现类
 * </p>
 *
 * @author hemiao
 * @since 2019-12-22
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
	
	@Autowired
	private SysUserMapper sysUserMapper;
	
	@Override
	public JsonTotalResult<List<SysUser>> selectPageList(SysUser sysUser, PageQuery pageQuery) {
		PageHelper.startPage(pageQuery.getCurrentPage(), pageQuery.getPageSize());
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>();
		Integer userType = sysUser.getUserType();
		if(!userType.equals(UserType.TYPE_1000.getCode())) {			
			queryWrapper.eq("main_user_id", sysUser.getMainUserId());
		}		
		queryWrapper.orderByDesc("create_time");
		List<SysUser> infoList = sysUserMapper.selectList(queryWrapper);
		PageInfo<SysUser> pageInfo = new PageInfo<SysUser>(infoList);	
		return new JsonTotalResult<List<SysUser>>(infoList, HttpCode.SUCCESS, pageInfo.getTotal());
	}

}
